package com.qdxwx.data.service.colleges;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.data.mapper.colleges.CollegesMapper;
import com.qdxwx.models.colleges.Colleges;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Service
public class CollegesServiceImpl implements CollegesService {

    @Autowired
    private CollegesMapper collegesMapper;

    @Override
    public int insert(Colleges colleges) {
        colleges.setCreateTime(LocalDateTime.now());
        return collegesMapper.insertColleges(colleges);
    }

    @Override
    public Colleges get(int id) {
        if (id < 1) return null;
        return collegesMapper.selectById(id);
    }

    @Override
    public List<Colleges> getList(Colleges colleges, PageRequest page) {
        return collegesMapper.selectList(colleges, page);
    }

    @Override
    public Integer count(Colleges colleges) {
        return collegesMapper.selectCount(colleges);
    }

    @Override
    public int update(Colleges colleges) {
        if (colleges.getId() < 1) return 0;
        colleges.setUpdateTime(LocalDateTime.now());
        return collegesMapper.updateColleges(colleges);
    }

    @Override
    public int delete(int id) {
        if (id < 1) return 0;
        return collegesMapper.deleteById(id);
    }

    @Override
    public int updateView(int id) {
        if (id < 1) return 0;
        return collegesMapper.updateView(id);
    }

    @Override
    public int updateLike(int id) {
        if (id < 1) return 0;
        return collegesMapper.updateLike(id);
    }
}
